package com.example.myapplication4.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.myapplication4.R;
import com.example.myapplication4.bean.Student;

import java.util.List;

public class MyArrayAdapter extends ArrayAdapter<Student> {
    public MyArrayAdapter(@NonNull Context context, List<Student> list) {
        super(context, 0, list);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        Student student = getItem(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(
                    R.layout.array_adapter_item, parent, false);
        }
        TextView nameText = convertView.findViewById(R.id.text1);
        TextView numberText = convertView.findViewById(R.id.text2);
        if (student != null) {
            nameText.setText(student.getName());
            numberText.setText(student.getNumber());
            convertView.setTag(student);
        }
        return convertView;
    }
}